<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/back/css/user/insertUser.css">
    <script src="/back/js/jquery-3.4.1.min.js"></script>
    <script src="/js/myAjax.js"></script>
    <script src="/js/myFileAjax.js"></script>
    <script src="/back/js/yanzheng.js"></script>
    <script src="/back/js/clean.js"></script>
</head>
<body>
<div class="jj">
    <div>
        <div class="content">
            <div class="text">用户名:</div>
            <div class="jk"><input type="text" id="username" placeholder="请输入5~15个字符" onblur="sname()"/></div>
        </div>
        <div><span id="name"></span></div>
        <div class="content">
            <div class="text">密码:</div>
            <div class="jk"><input type="password" id="password" placeholder="请设置密码"/></div>
        </div>
        <div class="content">
            <div class="text">确认密码:</div>
            <div class="jk"><input type="password" id="repassword" placeholder="再次输入密码" onblur="validate()"/></div>
        </div>
        <div><span id="tishi"></span></div>
        <div class="content">
            <div class="text">手机号:</div>
            <div class="jk"><input type="text" id="phone" onblur="phonets()"/></div>
        </div>
        <div><span id="phonets"></span></div>
        <div class="content">
            <div class="text">性别:</div>
            <div class="jk">
                <input type="radio" name="sex" value="保密" checked="checked"/>保密
                <input type="radio" name="sex" value="男"/>男
                <input type="radio" name="sex" value="女"/>女
            </div>
        </div>
        <div class="content">
            <div class="text">生日:</div>
            <div class="jk"><input type="date" id="birthday"/></div>
        </div>
        <div class="content">
            <div class="text">爱好:</div>
            <div class="jk">
                <input type="checkbox" name="hobby" value="游泳"/>游泳
                <input type="checkbox" name="hobby" value="跑步"/>跑步
                <input type="checkbox" name="hobby" value="打电动"/>打电动
            </div>
        </div>
        <div class="content">
            <div class="text">自我评价:</div>
            <div class="jk"><textarea id="introduce"></textarea></div>
        </div>
        <div class="content">
            <div class="button"><input class="button" type="button" value="清空" onclick="clean()"/></div>
            <div class="button"><input class="button" id="register" type="button" value="增加" onclick="register()"/>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    //注册========================================
    function register() {
        let data1 = {
            username:$("#username").val(),
            password:$("#password").val(),
            phone:$("#phone").val(),
            sex:$("input[name='sex']:checked").val(),
            birthday:$("#birthday").val(),
            hobby:hb(),
            introduce:$("#introduce").val(),
        };
        let data = myAjax('/back/user/regester',data1,'post');
        if (data.ending==1){
            alert("添加成功");
        }else {
            alert("添加失败");
        };
    }

    // 获得 复选框的值=====================================
    function hb() {
        let hb = [];
        $("input:checkbox[name='hobby']:checked").each(function () {
            let state = ($(this).prop('checked'));
            if (state) {
                hb.push($(this).val());
            }
        });
        hb = hb.join(',');
        return hb;

    }

    //第二次密码是否相同================

</script>
</html>